import React, { Component } from 'react'
import Items from "../components/item"
import axios from 'axios'
import "../style/index"

 class Classfil extends Component {
   state={
      arr1:[]
   }
  render() {
    let {arr1}=this.state;
    return (
      <div>
        {
          arr1&&arr1.map((item,index)=>{
             return  <Items item={item} key={index} handleParentStar={this.handleParentStar}
             handleParentLi={this.handleParentLi}></Items>
          })
        }
        
      </div>
    )
  }
  async componentDidMount(){
    let {type} = this.props.match.params;
    let res=await axios.get("/api/classfil")
    console.log(res);
    let list=res.data.classifylist.filter(item =>item.type==type)
    this.setState({  
      arr1:list
    })
  } 
  handleParentStar =(obj)=>{
    console.log('父组件',obj)
    let {arr1} = this.state;
    let ind = arr1.findIndex(item=> item.id == obj.id);
    arr1[ind].check = !arr1[ind].check;
    this.setState({
        arr1
    })
}
handleParentLi =(num,obj)=>{
    console.log(num,'ind');
    let {arr1} = this.state;
    let ind = arr1.findIndex(item=> item.id == obj.id);
    arr1[ind].ind = num;
    arr1[ind].check = false;
    this.setState({
        arr1
    })
}
 }
export default Classfil